package com.yonyou.pmclouds.reason.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.reason.entity.ProblemReasonVO;
import com.yonyou.pmclouds.reason.rmiimpl.ProblemReasonMaintainImpl;


public class ProblemReasonDeleteRefCheck implements SingleProcessor<ProblemReasonVO> {

    private ProblemReasonMaintainImpl maintain;

    public ProblemReasonDeleteRefCheck(ProblemReasonMaintainImpl maintain) {
        this.maintain = maintain;
    }

    @Override
    public void process(ProblemReasonVO vo, ProblemReasonVO orig) throws BusinessException {
        int status = maintain.getProblemReasonRefStatus(orig.getPkReason(), orig.getPkTenant());
        if (status == ProblemReasonMaintainImpl.STATUS_REF_BY_CHILD) {
            throw new BusinessException("当前问题原因已经存在下级问题原因，不可删除！");
        }
        if (status != ProblemReasonMaintainImpl.STATUS_NOT_REF) {
            throw new BusinessException("当前问题原因已经被引用，不可删除！");
        }
    }
}
